import dayjs from 'dayjs';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { useUserStore } from "/@/store/modules/user";

//类型
const modeFmt = ({text}: { text: any }) => {
  if (!text) return '';
  let color = text == '1' ? 'blue' : 'pink'
  return render.renderTag(render.renderDict(text, 'sealMode'), color)
}

//状态
const statFmt = ({text}: { text: any }) => {
  if (!text) return '';
  let color = 'red';
  if (text == '10' || text == '11') {
    color = 'green';
  } else if (text == '20' || text == '21') {
    color = 'red';
  } else if (text == '30') {
    color = 'blue';
  } else if (text == '40' || text == '41') {
    color = 'orange';
  }
  return render.renderTag(render.renderDict(text, 'sealStat'), color)
}

//, customRender: ({ text }) => render.renderDict(text, 'ddlxType')
export const columns: BasicColumn[] = [
  { title: '状态', dataIndex: 'stat', width: 28, customRender: statFmt },
  { title: '部门', dataIndex: 'ddlx', width: 30, customRender: ({ text }) => render.renderDict(text, 'ddlxType') },
  { title: '公司', dataIndex: 'companyId', width: 90, customRender: ({ text }) => render.renderDict(text, 'companys'), align: 'left', ellipsis: true },
  { title: '类型', dataIndex: 'type', width: 25, customRender: ({ text }) => render.renderDict(text, 'sealType') },
  { title: '方式', dataIndex: 'mode', width: 30, customRender: modeFmt },
  { title: '用途', dataIndex: 'content', width: 70, align: 'left' },
  { title: '申请人', dataIndex: 'createName', width: 33 },
  { title: '申请日期', dataIndex: 'createDate', width: 49, format: 'date|YYYY-MM-DD'},
  { title: '审批人', dataIndex: 'auditName', width: 33 },
  { title: '审批日期', dataIndex: 'auditDate', width: 49, format: 'date|YYYY-MM-DD' },
  { title: '确认人', dataIndex: 'backName', width: 33 },
  { title: '确认日期', dataIndex: 'backDate', width: 49, format: 'date|YYYY-MM-DD' },
];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  {
    label: '部门',
    field: 'ddlx',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'ddlxType@ddlxUser',
      placeholder: '请选择用章部门',
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    label: '公司',
    field: 'companyId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'companys',
      placeholder: '请选择公章公司',
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    label: '类型',
    field: 'type',
    component: 'JDictSelectTag',
    defaultValue: '1',
    componentProps: {
      dictCode: 'sealType',
      placeholder: '请选择公章类型',
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    label: '方式',
    field: 'mode',
    component: 'JDictSelectTag',
    defaultValue: '1',
    componentProps: {
      dictCode: 'sealMode',
      placeholder: '请选择用章方式',
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    label: '申请人',
    field: 'useName',
    component: 'Input',
    defaultValue: useUserStore().getUserInfo?.realname,
    required: true,
  },
  {
    label: '日期',
    field: 'useDate',
    component: 'DatePicker',
    defaultValue: dayjs(),
    required: true,
  },
  {
    label: '用途',
    field: 'content',
    component: 'Input',
    required: true,
  },
];
